package com.dc.refactoring._5_简化函数调用._12_ReplaceConstructorWithFactoryMethod.demo2;

/**
 * Description: 工厂函数，通过父类传参，统一生成子类
 * @author: gdc
 * @date: 2020/12/11
 * @version 1.0
 */
public abstract class Employee {

    public static final int ENGINEER = 0;
    public static final int SALESMAN = 1;
    public static final int MANAGER = 2;

    private int type;

    /**
     * 工厂函数，通过父类传参，统一生成子类
     */
    public static Employee create(int type) {
        switch (type) {
            case ENGINEER:
                return new Engineer();
            case SALESMAN:
                return new Salesman();
            case MANAGER:
                return new Manager();
            default:
                throw new IllegalArgumentException();
        }
    }

    // -------------------------------------


    /**
     * 通过明确函数创建子类
     */
    public static Employee createEngineer(){
        return new Engineer();
    }

    public static Employee createSalesman(){
        return new Salesman();
    }

    public static Employee createManager(){
        return new Manager();
    }

}
